package com.hkbigdata.sybx.service.ipml;

import com.hkbigdata.sybx.bean.UserRegedit;
import com.hkbigdata.sybx.mapper.UserRegeditMapper;
import com.hkbigdata.sybx.service.UserRegeditService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

@Service
public class UserRegeditServiceImpl implements UserRegeditService {

    @Autowired
    private UserRegeditMapper userRegeditMapper;

    @Override
    public List<UserRegedit> getAllUsers() {
        return userRegeditMapper.getAllUsers();
    }

    @Override
    public int addUser(UserRegedit userRegedit) {
        if (userRegedit.getUser_id() == null || userRegedit.getUser_id().trim().isEmpty()) {
            throw new IllegalArgumentException("账号不能为空");
        }
        if (userRegedit.getPassword_hash() == null || userRegedit.getPassword_hash().trim().isEmpty()) {
            throw new IllegalArgumentException("密码不能为空");
        }
        return userRegeditMapper.addUser(userRegedit);
    }

    @Override
    public UserRegedit getUserById(String user_id) {
        if (!StringUtils.hasText(user_id)) {
            throw new IllegalArgumentException("账号不能为空");
        }
        return userRegeditMapper.getUserById(user_id);
    }

    @Override
    public int updateUser(UserRegedit userRegedit) {
        if (userRegedit.getUser_id() == null || userRegedit.getUser_id().trim().isEmpty()) {
            throw new IllegalArgumentException("账号不能为空");
        }
        return userRegeditMapper.updateUser(userRegedit);
    }

    @Override
    public int deleteUser(String user_id) {
        if (!StringUtils.hasText(user_id)) {
            throw new IllegalArgumentException("账号不能为空");
        }
        return userRegeditMapper.deleteUser(user_id);
    }

    @Override
    public List<UserRegedit> findAll() {
        return userRegeditMapper.findAll();
    }
    // 文档5: UserRegeditServiceImpl.java
    @Override
    public int updatePassword(String userId, String passwordHash) {
        return userRegeditMapper.updatePassword(userId, passwordHash);
    }
}